$(function() {

        var ENUMER_INDEX = 1;
        var ENUMER_CREATE = 2;
        var ENUMER_LOGOUT = 3;
        var jsonData = [{
            "name": "首页",
            "url": "index.html",
            "type": ENUMER_INDEX,
        }, {
            "name": "创建会员",
            "url": "userCreate.html",
            "type": ENUMER_CREATE,
        }, {
            "name": "账号退出",
            "url": "login.html",
            "type": ENUMER_LOGOUT,
        }];
        $(".iconline-menu2").on(A.options.clickEvent, function() {
            var template = '';

            if (jsonData.length > 0) {
                template += '<ul class="ex-listitem">';
                var itemList = "";
                $.each(jsonData, function() {
                    var item = "<li data-type='" + this.type + "'>" + this.name + "</li>";
                    itemList += item;
                });
                template += itemList + "</ul>";

            }
            showMenu(template);
            return false;
        });
        $(".menu").on(A.options.clickEvent, function(e) {
            var id = $(e.currentTarget).attr("id");
            window.localStorage.setItem("target", id);
            var url = $(e.currentTarget).attr("href");
            $(".menu-text").css("color", "#434343");
            $(".menubar a").removeAttr("style");
            $(e.currentTarget).find(".menu-text").css("color", "#60d296");
            $(e.currentTarget).css("border-bottom", "2px solid #60d296");
            window.location.href = url;
            return false;
        });
        $(".createbtn").on(A.options.clickEvent, function() {
            window.location.href = "userCreate.html";
        });
        $("#login_btn").on(A.options.clickEvent, function() {
            //登陆的逻辑TODO
            //这段代码主要是模仿登陆的效果
            A.showMask(function() {
                A.showToast('登录成功');
                window.localStorage.clear();
                setTimeout(function() {
                    window.location.href = "index.html";
                }, 500);

            });
            setTimeout(function() {
                A.hideMask();
            }, 2000);
            return false;
        });
        $('input[type="file"]').on("change", function(e) {
            console.log($(e.currentTarget).val());
        });
        var getFullpath = function(obj) {
            if (obj) {
                //ie 
                if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
                    obj.select();
                    return document.selection.createRange().text;
                }
                //firefox 
                else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
                    if (obj.files) {
                        return obj.files.item(0).getAsDataURL();
                    }
                    return obj.value;
                }
                return obj.value;
            }
        }
            var showMenu = function(template) {
                var $popup = A.popup({
                    html: template,
                    css: {
                        width: '100%',
                        'margin-top': '44px'
                    },
                    pos: 'top'
                });
                $popup.popup.find('.ex-listitem li').on(A.options.clickEvent, function(e) {
                    var type = $(e.currentTarget).data("type");
                    $.each(jsonData, function() {
                        if (type == this.type) {
                            if (type == ENUMER_LOGOUT) {
                                var url = this.url;
                                A.confirm('提示', '你确定要退出?', function() {
                                    window.location.href = url;
                                }, function() {

                                });
                            } else {
                                window.location.href = this.url;
                            }
                            return false;
                        }

                    });
                    $popup.close();
                });
            };
            var activeMenu = function(id) {
                $.each($(".menubar a"), function() {
                    if ($(this).attr("id") == id) {
                        $(this).find(".menu-text").css("color", "#60d296");
                        $(this).css("border-bottom", "2px solid #60d296");
                        return false;
                    }
                });
            };
            var initMenu = function() {
                $.each($(".menu"), function() {
                    if (this.id == 'basic') {
                        this.href = "personIndex.html";
                    } else if (this.id == 'job') {
                        this.href = "jobIndex.html";
                    } else if (this.id == 'social') {
                        this.href = "socialContact.html";
                    } else if (this.id == 'zentrust') {
                        this.href = "interaction.html";
                    }
                });
                var id = window.localStorage.getItem("target");
                if (id == null || id == undefined) {
                    activeMenu('basic');
                } else {
                    activeMenu(id);
                }
            };
            initMenu();

        });